﻿<UserControl x:Class="Microsoft.Forums.ForumsClient.Views.ForumFolderView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ForumsClient="clr-namespace:Microsoft.Forums.ForumsClient"
    xmlns:Models="clr-namespace:Microsoft.Forums.ForumsClient.Models"
    xmlns:Views="clr-namespace:Microsoft.Forums.ForumsClient.Views">
    <UserControl.Resources>
        
        <Style TargetType="TreeViewItem">
            <EventSetter Event="MouseRightButtonDown" Handler="TreeViewItem_MouseRightButtonDown" />
        </Style>
        <Views:ForumStoreTitleConverter  x:Key="ForumStoreTitleConverter" />
        <Views:FormatToStringConverter x:Key="FormatUnreadPosts" />
        <ContextMenu x:Key="ForumItemContextMenu">
            <MenuItem x:Uid="MenuItem_1" Header="Synchronize" Command="{x:Static ForumsClient:Commands.SynchronizeForum}"/>
            <MenuItem x:Uid="MenuItem_2" Header="Unsubscribe" Command="{x:Static ForumsClient:Commands.UnsubscribeForum}"/>
        </ContextMenu>

        <ContextMenu x:Key="ForumListHeaderContextMenu">
            <MenuItem x:Uid="MenuItem_3" Header="Synchronize All" Command="{x:Static ForumsClient:Commands.SynchronizeAllForums}"/>
        </ContextMenu>
        
        <DataTemplate x:Uid="DataTemplate_1" x:Key="ForumHeaderTemplate">
            <StackPanel x:Uid="StackPanel_2" Orientation="Horizontal" ContextMenu="{StaticResource ForumListHeaderContextMenu}">
                <Image x:Uid="Image_2" Margin="0,0,0,0" Width="16" Height="16" Stretch="Fill" Source="Images\MSForumsClient.png"/>
                <TextBlock x:Uid="TextBlock_1" Margin="3,0,0,0">Forums</TextBlock>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Uid="DataTemplate_2" x:Key="ForumItem">
            <DockPanel x:Uid="DockPanel_2" ContextMenu="{StaticResource ForumItemContextMenu}">
                <ForumsClient:WaitThrobber Margin="0,0,3,0" Radius="16" Throb="{Binding Path=IsSyncInProgress}"   />
                <Image x:Uid="Image_3" Margin="0,0,0,0" Width="16" Height="16" Source="Images\folder.ico" Stretch="Fill" />
                <TextBlock x:Uid="TextBlock_2" Margin="3 0 0 0" VerticalAlignment="center" ToolTip="{Binding Path=Name}" Text ="{Binding Path=Name}"/>
                <TextBlock x:Uid="TextBlock_3" Margin="3 0 0 0" Foreground="Blue"  VerticalAlignment="center" Text ="{Binding Path=Forum.UnreadPostCount, Converter={StaticResource FormatUnreadPosts}, ConverterParameter='\(\{0\}\)'}" />
        </DockPanel>
        </DataTemplate>
    </UserControl.Resources>
    
        <DockPanel LastChildFill="True" Width="Auto" HorizontalAlignment="Stretch" x:Uid="FolderPaneControl"  x:Name="FolderPaneControl">
            <Expander x:Uid="ForumFolderExpander" 
                      DockPanel.Dock="Top" 
                      IsExpanded="True" Margin="0,0,0,0"  
                      Width="Auto" Height="Auto" 
                      Header="Forum Folders"  
                      FontSize="11" 
                      FontWeight="Bold"  
                      Grid.IsSharedSizeScope="False" 
                      x:Name="ForumFolderExpander" 
                      BorderThickness="0,0.5,0,0" 
                      HorizontalContentAlignment="Stretch" 
                      VerticalContentAlignment="Stretch"
                      >
                <TreeView  x:Uid="forumTreeView" BorderBrush="{x:Null}" BorderThickness="0,0,0,0" x:Name="forumTreeView"   
                                          ScrollViewer.VerticalScrollBarVisibility="Auto" 
                                          ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                                          SelectedItemChanged="forumTreeView_SelectedItemChanged" Background="Transparent">
                    <TreeViewItem x:Uid="ForumStoreFolder" x:Name="ForumStoreFolder" IsExpanded="True" >
                        <TreeViewItem.Header>
                            <StackPanel x:Uid="StackPanel_2" Orientation="Horizontal">
                                <Image x:Uid="Image_1" Margin="0,0,0,0" Width="16" Height="16" Stretch="Fill" Source="Images\MSForumsClient.png"/>
                                <TextBlock x:Uid="ForumStoreFolderText" x:Name="ForumStoreFolderText" Margin="3,0,0,0" FontWeight="Normal" 
                                           Text="{Binding Path=CurrentUser.LogOnState, Converter={StaticResource ForumStoreTitleConverter}}" />
                            </StackPanel>
                        </TreeViewItem.Header>
                    <TreeViewItem x:Uid="MyThreads"  Header="{Binding MyThreadsFolder}" />
                    <TreeViewItem x:Uid="Forum"  IsExpanded="True" HeaderTemplate="{StaticResource ForumHeaderTemplate}" 
                                      ItemsSource="{Binding Path=SubscribedForums}" ItemTemplate="{StaticResource ForumItem}" />

                    </TreeViewItem>
                </TreeView>
            </Expander>
        </DockPanel>
    
</UserControl>
